home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="utf-8"?>
- <!-- ===========================================================
- Category: XSLT
- Sub-category: xsl:attribute
- Author: David Silverlight
- HeadGeek@xmlpitstop.com
- Created: 2001-05-16
- Description:-
- This stylesheet processes a set of XML elements and uses the
- xsl:attribute element to generate a new xml file containing
- atrributes from the original xml document as well as new
- attributes created with xslt functions like a
- substring-before, substring-after and others.
- ================================================================ -->
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
- <xsl:output method="xml"/>
-
- <!-- Template for root rule -->
- <xsl:template match="/">
- <xsl:apply-templates/>
- </xsl:template>
-
-
- <!-- Template for "employees" elements -->
- <xsl:template match="employees">
- <!--This stylesheet processes a set of XML elements and
- uses the xsl:attribute element to generate a new xml file containing
- atrributes from the original xml document as well as new attributes
- that are created through variable.-->
-
- <!-- Generate the "bademployees" root element -->
- <xsl:element name="bademployees" >
-
-
-
- <xsl:for-each select="employee[department='Sales']" >
-
- <xsl:sort select="department" order="ascending" />
- <xsl:element name="employee" >
-
- <!-- Create of the department attribute. -->
- <xsl:attribute name="department" >
- <!-- Set the value of the attribue based on the department -->
- <xsl:value-of select="department" />
- </xsl:attribute>
-
-
- <!-- Here we are creating an attribute that is a variation from
- the original source document. In this example we are breaking
- up employee name and creating two new attributes from it (firstname and lastname) -->
- <xsl:attribute name="firstname">
- <xsl:value-of select="substring-before(employeename, ' ')" />
- </xsl:attribute>
-
-
- <!-- We can also create and set variables to be used as our attribute
- values. Note: We are doing the same as with firstname
- but just accomplishing it with the use of an xsl:varialbe. -->
- <xsl:attribute name="lastname">
- <xsl:variable name="lastname" select="substring-after(employeename, ' ')" />
- <xsl:value-of select="$lastname" />
- </xsl:attribute>
-
- <!-- Here we are creating a new attribute set to a value that we define -->
- <xsl:attribute name="new" >
- <xsl:value-of select="'new and exciting attribute'" />
- </xsl:attribute>
-
- </xsl:element>
- </xsl:for-each>
- </xsl:element>
- </xsl:template>
-
-
-
- </xsl:stylesheet>